#!/bin/bash

#使用命令 ./package.sh prd

mode='test' # prd pre test

if [[ "$1" ]]; then
    mode=$1
fi

if [ -d './dist' ]; then
  rm -rf ./dist
  rm -rf ./dist.zip
fi

echo "正在打包${mode}环境的包============"
beginTime=$(date "+%Y-%m-%d %H:%M:%S")

if [[ $mode == 'test' ]]; then
  npm run build
else
  npm run "build:${mode}"
fi

endTime=$(date "+%Y-%m-%d %H:%M:%S")
duration=$(($(date +%s -d "${endTime}")-$(date +%s -d "${beginTime}")));
echo "打包时间:" $duration"s"

zip -r ./dist.zip ./dist
start $(pwd)

#  使用read命令达到类似bat中的pause命令效果
echo 按任意键继续
read -n 1